<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\CoAgreement;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Controllers\AdminController;

class CoAgreementController extends AdminController
{
    protected $title = '协议管理';
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new CoAgreement(), function (Grid $grid) {
            $grid->id->sortable();
//            $grid->text;
            $grid->type->display(function ($v){
                if($v == 1){
                    return '用户协议';
                }else{
                    return '配送协议';
                }
            });
//            $grid->created_at;
            $grid->updated_at->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
            $grid->disableDeleteButton();
            $grid->disableViewButton();
            $grid->disableCreateButton();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new CoAgreement(), function (Show $show) {
            $show->id;
            $show->text;
            $show->type;
            $show->created_at;
            $show->updated_at;
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new CoAgreement(), function (Form $form) {
            $form->hidden('id');
//            $form->radio('type')->options(['1'=>'用户协议','3'=>'配送协议'])->disable();
            $form->editor('text');
//            $form->hidden('created_at');
//            $form->hidden('updated_at');
            $form->disableViewButton();
            $form->disableDeleteButton();
        });
    }
}
